<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            margin: 0 auto;
        }
        body{
            background-color: #343a40;
        }
    </style>
</head>
<body>
<h1>登录页面</h1>
<div style="width: 500px;height: 500px; background-color: #8EC5FC;">
    <form action="">
        <div> <input type="text" name="username" placeholder="请输入用户名"></div>
        <div> <input type="password" name="password" placeholder="请输入密码"></div>
        <div><input type="button" value="按钮" @click="login()"></div>
    </form>
</div>
</body>
<!--引入Vue和axios-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"></script>
<script>
    let longin_v = new Vue({
        el:"form",
        data:{
            user:"",
        },
        methods:{
            login:function (){
                let data = new FormData(document.querySelector("form"));
                axios.post("/login",data).then(function (response){
                    if (response.data==1){
                        location.href = "/"
                    }else if (response.data==2){
                        alert("密码错误!!!")
                    }else {
                        alert("用户名不存在!!!")
                    }
                })
            },

        }
    })
</script>
</html>